package com.jian.springbootdempapi.controller;

import com.jian.springbootdempapi.model.dto.NameRequest;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/demo")
public class demoApi {

    @GetMapping("/name")
    public String getName(@RequestBody NameRequest name) {
        return "get:你好," + name.getName();
    }

    @PostMapping("/name")
    public String postName(@RequestParam String name) {
        return "post-param:你好," + name;
    }

    @PostMapping("/json")
    public String postJsonName(@RequestBody NameRequest name) {
        return "post-body:你好," + name.getName();
    }

    @GetMapping("/time")
    public String getCurrentTime(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(System.currentTimeMillis());
    }
}